/// @tags:
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long ULL;

constexpr int MAXN = 100, P1 = 1e9 + 9, P2 = 20040703, SPEED = 1e8;

int c[MAXN], a[MAXN];

template <ULL P, typename B_Type>
B_Type qpow(B_Type base, int index) {
  B_Type res = 1;
  while (index) {
    if (index & 1) res = res * base % P;
    base = base * base % P;
    index >>= 1;
  }
  return res;
}

inline int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) cin >> c[i] >> a[i];
    ULL ans1 = 0;
    int lim = SPEED / n / t / 16;
    for (int x = 2; x <= lim; ++x) {
      for (int i = 0; i < n; ++i) {
        ULL exp = qpow<P1>(static_cast<ULL>(x), a[i]);
        ans1 += c[i] * (exp * x - exp);
      }
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("div.in", "r", stdin);
  freopen("div.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
